﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using ModelCoding.Entity;
using ModelCoding.Helpers;
using ModelCoding.IServices;
using ModelCoding.Services;
using ModelCoding.View;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;

namespace ModelCoding.ViewModel
{
    public class MainViewModel: ViewModelBase
    {
        public MainViewModel()
        {
           
            ChangeMenu = new RelayCommand<string>(name=> ChangeMenuMethod(name));

            Min = new RelayCommand<Window>(win=> {
                win.WindowState = WindowState.Minimized;
            });
            Close = new RelayCommand<Window>(win => {
                win.Close();
            });

            Page = new WelCome();
        }

        private void ChangeMenuMethod(string Name)
        {

            Name = "ModelCoding.View." + Name;
            var types = Type.GetType(Name);
            if (types == null)
            {
                DialogHelper.ShowDialog($"未找到该页面：{Name}，请加载其他界面！");
                return;
            }
            Page = Activator.CreateInstance(types);
        }


        public RelayCommand<string> ChangeMenu { get; set; }
        public RelayCommand<Window> Min { get; set; }
        public RelayCommand<Window> Close { get; set; }


        private Object _Page;

        public Object Page
        {
            get { return _Page; }
            set { _Page = value;RaisePropertyChanged(); }
        }







    }
}
